﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Geldtransporter
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        private Transporter transporter;
        public MainWindow()
        {
            InitializeComponent();
        }

        private void OpenFile(object sender, RoutedEventArgs e)
        {


            // Create OpenFileDialog

            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();



            // Set filter for file extension and default file extension

            openFileDialog.DefaultExt = ".txt";

            openFileDialog.Filter = "Text documents (.txt)|*.txt";



            // Display OpenFileDialog by calling ShowDialog method

            Nullable<bool> result = openFileDialog.ShowDialog();



            // Get the selected file name and display in a TextBox

            if (result == true)
            {
                ReadFile file = new ReadFile(openFileDialog.FileName);

                transporter = new Transporter(file.GetKofferList());

                listLeft.ItemsSource = transporter.LeftStack.BagList;
                listRight.ItemsSource = transporter.RightStack.BagList;

                this.updateLabels();
            }

        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < 100; i++)
            {
                transporter.OptimizeMoney();
            }

            for (int i = 0; i < 100; i++)
            {
                transporter.OptimizeWeight();
            }
          

            this.updateLabels();
        }

        private void updateLabels()
        {
            moneyLeft.Text = "Geld: " + transporter.LeftStack.TotalMoney().ToString() + "€";
            moneyRight.Text = "Geld: " + transporter.RightStack.TotalMoney().ToString() + "€";

            weightLeft.Text = "Gewicht: " + transporter.LeftStack.TotalWeight().ToString() + "kg";
            weightRight.Text = "Gewicht: " + transporter.RightStack.TotalWeight().ToString() + "kg";


            moneyDifference.Text = "GeldDifferenz: " + (transporter.LeftStack.TotalMoney() - transporter.RightStack.TotalMoney()) + "€";
            weightDifference.Text = "Gewichtsdifferenz: " + (transporter.LeftStack.TotalWeight() - transporter.RightStack.TotalWeight()) + "kg";

        }



    }
}
